//
//  MPTLiveApplyView.m
//  MPTLive
//
//  Created by caixun on 15/8/21.
//  Copyright (c) 2015年 Jeakin. All rights reserved.
//

#import "MPTLiveApplyView.h"
#import "UIColor+MPTColor.h"
#import "UIFont+MPTFont.h"


@interface MPTLiveApplyView ()

// 申请页面提示文字
@property (nonatomic, strong) UILabel *applyTitle;
// 申请页面提示文字
@property (nonatomic, strong) UILabel *applyMessage;
// 去秒拍看直播按钮
@property (nonatomic, strong) UIButton *goMPBtn;
// 立即申请内测资格按钮
@property (nonatomic, strong) UIButton *applyBtn;
// 返回按钮
@property (nonatomic, strong) UIButton *goBackBtn;

@end


@implementation MPTLiveApplyView


#pragma mark - ***************************** View Lifecycle ***********************************

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self initMainViews];
    }
    return self;
}

-(void)willMoveToSuperview:(UIView *)newSuperview
{
    [super willMoveToSuperview:newSuperview];
    
    if(newSuperview == nil)
    {
        [[self subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
        
        return ;
    }
}


#pragma mark - ******************************** Init All Views **********************************

- (void)initMainViews
{
    UIImageView *bgImgv = [[UIImageView alloc] initWithFrame:self.frame];
    
    UIImage *bgImg = nil;
    if(iPhone4)
    {
        bgImg = [UIImage imageNamed:@"ApplyViewBg_4"];
    }
    else if(iPhone5)
    {
        bgImg = [UIImage imageNamed:@"ApplyViewBg_5"];
    }
    else if(iPhone6)
    {
        bgImg = [UIImage imageNamed:@"ApplyViewBg_6"];
    }
    else if(iPhone6p)
    {
        bgImg = [UIImage imageNamed:@"ApplyViewBg_6p"];
    }
    else
    {
        bgImg = [UIImage imageNamed:@"ApplyViewBg_6p"];
        bgImgv.contentMode = UIViewContentModeScaleAspectFit;
    }
    bgImgv.image = bgImg;
    [self addSubview:bgImgv];
    
    // 看直播去秒拍按钮
    CGRect goMPRect = CGRectMake(20,
                                    screenH-30-44,
                                    screenW-20*2,
                                    44);
    self.goMPBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.goMPBtn.frame = goMPRect;
    [self.goMPBtn setTitle:@"看直播去秒拍" forState:UIControlStateNormal];
    [self.goMPBtn setBackgroundColor:[UIColor YXColorWithHexCode:@"#ffe200"]];
    [self.goMPBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.goMPBtn.layer.cornerRadius = 22;
    self.goMPBtn.titleLabel.font = [UIFont YXFontOfSize:16.0f];
    [self addSubview:self.goMPBtn];
    
    // 申请资格提示文字
    CGRect applyMessageRect = CGRectMake(0,
                                         self.goMPBtn.frame.origin.y-70,
                                         screenW*0.5 + 20,
                                         30);
    self.applyMessage = [[UILabel alloc] initWithFrame:applyMessageRect];
    self.applyMessage.text = @"账号暂不符合要求，点击";
    self.applyMessage.enabled = NO;
    self.applyMessage.font = [UIFont YXFontOfSize:16.0f];
    self.applyMessage.textAlignment = NSTextAlignmentRight;
    self.applyMessage.textColor = [UIColor whiteColor];
    self.applyMessage.backgroundColor = [UIColor clearColor];
    [self addSubview:self.applyMessage];
    
    // 立刻申请内测资格按钮
    CGRect applyMPRect = CGRectMake(self.applyMessage.frame.size.width+5,
                                 self.applyMessage.frame.origin.y,
                                 screenW*0.5 - 20,
                                 self.applyMessage.frame.size.height);
    self.applyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.applyBtn.frame = applyMPRect;
    [self.applyBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [self.applyBtn setTitle:@"立即申请直播资格" forState:UIControlStateNormal];
    self.applyBtn.titleLabel.font = [UIFont YXFontOfSize:16.0f];
    [self.applyBtn setTitleColor:[UIColor YXColorWithHexCode:@"#ffe200"] forState:UIControlStateNormal];
    [self addSubview:self.applyBtn];
    
    // 申请资格提示文字
    CGRect applyTitleRect = CGRectMake(0,self.applyMessage.frame.origin.y-40,screenW,30);
    self.applyTitle = [[UILabel alloc] initWithFrame:applyTitleRect];
    self.applyTitle.text = @"欢迎来到秒拍直播";
    self.applyTitle.font = [UIFont YXFontOfSize:18.0f];
    self.applyTitle.textAlignment = NSTextAlignmentCenter;
    self.applyTitle.textColor = [UIColor whiteColor];
    self.applyTitle.backgroundColor = [UIColor clearColor];
    [self addSubview:self.applyTitle];
    
    // 返回按钮
    UIImage *back = [UIImage imageNamed:@"CommonBack"];
    UIImage *backPress = [UIImage imageNamed:@"CommonBackPress"];
    CGRect backRect = CGRectMake(0, 0, 44, 60);
    self.goBackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.goBackBtn.frame = backRect;
    [self.goBackBtn setImage:back forState:UIControlStateNormal];
    [self.goBackBtn setImage:backPress forState:UIControlStateHighlighted];
    [self addSubview:self.goBackBtn];
}


#pragma mark - ****************************** Functions *********************************

- (void)setTargetForBtn:(id)target
        withApplyAction:(SEL)applyAction
         withGoMPAction:(SEL)goMPAction
       withGoBackAction:(SEL)goBackAction
{
    [self.goMPBtn addTarget:target action:goMPAction forControlEvents:UIControlEventTouchUpInside];
    [self.applyBtn addTarget:target action:applyAction forControlEvents:UIControlEventTouchUpInside];
    [self.goBackBtn addTarget:target action:goBackAction forControlEvents:UIControlEventTouchUpInside];
}


@end
